import os

def get_env_var(var_name, default_value):
    """判断环境变量是否存在如果美欧则返回默认值"""
    return os.getenv(var_name, default_value)

class Config:
    # 应用密钥和安全配置
    SECRET_KEY = get_env_var('SECRET_KEY', 'your_default_secret_key')
    SECURITY_PASSWORD_SALT = get_env_var('SECURITY_PASSWORD_SALT', 'your_password_salt')
    JWT_SECRET_KEY = get_env_var('JWT_SECRET_KEY', 'your_jwt_secret_key')
    
    # 数据库配置
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))  # 获取当前文件的绝对路径
    SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URI', f'sqlite:///{os.path.join(BASE_DIR, "database/default.db")}')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLITE_ENCRYPTION_KEY = get_env_var('SQLITE_ENCRYPTION_KEY', '98b2ee18-f03b-4090-b180-7a9cf54f1ef4')
    
    
    # 电子邮件服务器配置 暂时不计划写这功能先预留
    MAIL_SERVER = get_env_var('MAIL_SERVER', 'smtp.example.com')
    MAIL_PORT = int(get_env_var('MAIL_PORT', 587))
    MAIL_USE_TLS = get_env_var('MAIL_USE_TLS', 'true').lower() in ['true', '1', 't']
    MAIL_USERNAME = get_env_var('MAIL_USERNAME', None)
    MAIL_PASSWORD = get_env_var('MAIL_PASSWORD', None)
    MAIL_DEFAULT_SENDER = get_env_var('MAIL_DEFAULT_SENDER', 'noreply@example.com')
    
    # 调试和日志
    DEBUG = get_env_var('DEBUG', 'true').lower() in ['true', '1', 't']
    LOG_LEVEL = get_env_var('LOG_LEVEL', 'DEBUG')
    LOG_FILE_PATH = get_env_var('LOG_FILE_PATH', 'logs/app.log')

config = Config()
